/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.web.dao;

import com.web.entity.Test;
import com.web.service.Testdaoimpl;
import com.web.util.DatabaseUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author liqianru
 */
public class Basedata {

    public static Object datadml(String rowname, String rowvalue) {
        Connection con = null;
        //4.创建一个Statement执行SQL语句
        PreparedStatement ps = null;
        ResultSet rset = null;
        con = DatabaseUtil.getConnection();
        try {
            ps = con.prepareStatement("select * from TestQuestions where ?=?");
            ps.setString(1, rowname);//在SQL语句中设置值
            ps.setString(2, rowvalue);
            rset = ps.executeQuery();//将查询结果返回成一个结果集对象
            if (rset.next()) {
                return new Test(
                        rset.getString(1),
                        rset.getString(2),
                        rset.getString(3),
                        rset.getString(4),
                        rset.getString(5),
                        rset.getString(6),
                        rset.getInt(7),
                        rset.getString(8));
            }
        } catch (SQLException ex) {
            Logger.getLogger(Testdaoimpl.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            DatabaseUtil.close(rset, ps, con);
        }
        return null;
    }
}
